<?php

namespace App\Http\Controllers\Api\Sign;

use App\Http\Controllers\Api\Controller;
use App\Http\Requests\Api\SignUserRequest;
use App\Models\Sign\SignUser;
use App\Models\Sign\UserProject;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class UserWxController extends Controller
{
    //

    //返回当前登录用户信息:报考信息
    public function info(Request $request){

        $user_openid = $request->weixin_openid;

        $user = User::where('weixin_openid',$user_openid)->first();

        //$user = Auth::guard('api')->user();
        //查看用户“个人信息”是否登记
        $sign_data =SignUser::where('u_id',$user->id)->first();

        if(empty($sign_data)){
            //用户没有录入个人信息
            return $this->failed('请填写个人信息','400');
        }else{
            //返回用户的报考专业信息
            $project_data = UserProject::where('identity',$sign_data->identity)->get();
            return $this->success($project_data);
        }

    }


    //添加用户：用户登记个人基本信息
    public function userAdd(SignUserRequest $request)
    {

        $user_sum = Auth::guard('api')->user();

        $user = SignUser::create([
            'u_id'=>$user_sum->id,
            'name'=>$request->name,//用户
            'identity'=>$request->identity,//身份证
            'phone'=>$request->phone,//电话号码
            'teacher'=>$request->teacher,//咨询师
        ]);

        return $this->success($user);

    }

}
